package com.example.SBootDemo.ExceptionHandel;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import com.example.SBootDemo.ExceptionHandel.exception.Myexception;


/**
 * 统一错误信息处理
 * @author 944658413
 *
 */

@ControllerAdvice
class ExceptionHandel {
	
    @SuppressWarnings("unchecked")
    //选择要处理的自定义错误类型
	@ExceptionHandler(value=Myexception.class)
    //返回json格式数据
	@ResponseBody
    public Map defaultErrorHandler(HttpServletRequest req, Exception e) throws Exception {
       Map m = new HashMap();
       m.put("messageType", "数据库查询");
       m.put("errMessage",e.getMessage());
       m.put("code", "123456");
        return m;
    }
}
